<?php $this->_extends('../_layouts/default_layout'); ?>
<?php $this->_block('contents'); ?>
<link type="text/css" href="<?=Q::ini('custom_system/base_url')?>css/jq.mselect.css" rel="stylesheet" />
<script type="text/javascript" src="<?=Q::ini('custom_system/base_url')?>js/highstock.js"></script>
<script type="text/javascript" src="<?=Q::ini('custom_system/base_url')?>js/exporting.js"></script>
<script type="text/javascript" src="<?=Q::ini('custom_system/base_url')?>js/jq.mselect.js?"></script>
<script type="text/javascript" src="<?=Q::ini('custom_system/base_url')?>js/jq.multiselect.js"></script>
<script type="text/javascript">
$(function(){
	$(".datepicker").datepicker({dateFormat: 'yy-mm-dd', changeMonth: true});	
	$("#warehouse_multiselect").multiselect({height: 260, minWidth: 160});
	var product_categories_data = <?=$product_categories?>;
	$(document).mselect(product_categories_data, 'product_categories_id', 'product_categories_id', "<?=isset($_GET['product_categories_id']) ? $_GET['product_categories_id'] : 0?>");
	$(".button").click(function(){
		$("#inventory_chart_form").submit();
		$(this).attr('disabled', true);
	});
	<?if (isset($_GET['is_search']) && isset($show_chart)):?>
	var data = <?=isset($data_json) ? $data_json : 0?>;
	window.chart = new Highcharts.StockChart({
		chart: {renderTo: 'report_chart'},
		credits: {enabled: false},
		rangeSelector: {selected: 1},
		title: {text: '<strong><?=isset($warehouse_name) ? $warehouse_name : ''?>库存数量和金额统计图表</strong>'},
		series: data
	});
	<?endif;?>
});
</script>
<fieldset><legend>查询条件</legend>
<form method="get" id="inventory_chart_form">
<?include (Q::ini('custom_system/elements_dir') . 'searchform_element.php');?>
<table class="form_table">
<tr>
	<th>统计时间</th>
	<td>
		<input type="text" class="datepicker" name="begin_report_time" value="<?=isset($_GET['begin_report_time']) ? $_GET['begin_report_time'] : date('Y-m-01', CURRENT_TIMESTAMP)?>" /> to
		<input type="text" class="datepicker" name="end_report_time" value="<?=isset($_GET['end_report_time']) ? $_GET['end_report_time'] : date('Y-m-d', CURRENT_TIMESTAMP)?>" />
	</td>
</tr>
<tr>
	<th><input type="checkbox" name="by_current_categories" value="1" <?=isset($_GET['by_current_categories']) ? 'checked="checked"' : ''?>/> 产品分类</th>
	<td>
		<input type="hidden" id="product_categories_id" name="product_categories_id" />
	</td>
</tr>
<tr>
	<th>仓库</th>
	<td>
		<select name="warehouse[]" multiple="multiple" id="warehouse_multiselect">
			<?foreach ($warehouse as $w):?>
			<option value="<?=$w['id']?>" <?if (isset($_GET['warehouse']) && is_array($_GET['warehouse']) && in_array($w['id'], $_GET['warehouse']))echo "selected='selected'"?>><?=$w['name']?></option>
			<?endforeach;?>
		</select>
	</td>
</tr>
<tr>
	<td colspan="2">
		<input type="hidden" name="is_search" value="1" />
		<input type="submit" class="button" value="提交" />
	</td>
</tr>
</table>
</form>
</fieldset>
<?if (isset($_GET['is_search']) && isset($show_chart)):?>
<table class="list_table" width="40%">
<tr>
	<th>分类名</th>
	<th>平均金额</th>
	<th>平均数量</th>
	<th>金额占率</th>
	<th>数量占率</th>
</tr>
<?foreach ($report['report'] as $r):?>
<tr>
	<td><?=$r['name']?></td>
	<td><?=$r['amount']?></td>
	<td><?=$r['quantity']?></td>
	<td><?=empty($report['total_report_amount']) ? '0' : sprintf('%.2f', $r['amount'] / $report['total_report_amount'] * 100)?>%</td>
	<td><?=empty($report['total_report_quantity']) ? '0' : sprintf('%.2f', $r['quantity'] / $report['total_report_quantity'] * 100)?>%</td>
</tr>
<?endforeach;?>
<tr>
	<th>合计</th>
	<td><?=$report['total_report_amount']?></td>
	<td><?=$report['total_report_quantity']?></td>
	<td></td>
	<td></td>
</tr>
</table>
<br />
<div style="border: 1px solid #aaa">
	<div id="report_chart" style="height: 500px; min-width: 800px"></div>
</div>
<?endif;?>
<?php $this->_endblock('contents'); ?>